/*      */ package dm.jdbc.dataConvertion;
/*      */ 
/*      */ import dm.jdbc.dbaccess.DBError;
/*      */ import dm.jdbc.desc.CommDesc;
/*      */ import dm.jdbc.desc.DTypeInfo;
/*      */ import dm.jdbc.desc.LobDesc;
/*      */ import dm.jdbc.driver.DmdbBlob;
/*      */ import dm.jdbc.driver.DmdbClob;
/*      */ import dm.jdbc.driver.DmdbConnection_bs;
/*      */ import dm.jdbc.driver.DmdbInputStream;
/*      */ import dm.jdbc.util.UtilBinaryToUnicodeInputStream;
/*      */ import dm.sql.ARRAY;
/*      */ import dm.sql.DmdbDateTime;
/*      */ import dm.sql.DmdbIntervalDT;
/*      */ import dm.sql.DmdbIntervalYM;
/*      */ import dm.sql.DmdbSQLInput;
/*      */ import dm.sql.DmdbTime;
/*      */ import dm.sql.DmdbTimeZone;
/*      */ import dm.sql.DmdbTimeZone2Bdta;
/*      */ import dm.sql.STRUCT;
/*      */ import dm.sql.TypeData;
/*      */ import dm.sql.TypeDescriptor;
/*      */ import java.io.BufferedReader;
/*      */ import java.io.ByteArrayInputStream;
/*      */ import java.io.InputStream;
/*      */ import java.io.InputStreamReader;
/*      */ import java.io.Reader;
/*      */ import java.io.StringReader;
/*      */ import java.math.BigDecimal;
/*      */ import java.math.BigInteger;
/*      */ import java.sql.Blob;
/*      */ import java.sql.Clob;
/*      */ import java.sql.Date;
/*      */ import java.sql.SQLData;
/*      */ import java.sql.SQLException;
/*      */ import java.sql.Time;
/*      */ import java.sql.Timestamp;
/*      */ import java.util.Map;
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ public class CType2JType
/*      */ {
/*      */   public static Object getAllBySqlType(int sqlType, byte[] val, CommDesc desc, int stmtHandle, long rowid, DmdbConnection_bs conn, Map map, String typeName, boolean isBdta)
/*      */     throws SQLException
/*      */   {
/*   50 */     switch (sqlType)
/*      */     {
/*      */     case -7: 
/*      */     case 16: 
/*   54 */       return new Boolean(getBoolean(val, desc, stmtHandle, conn));
/*      */     
/*      */     case -6: 
/*      */     case 4: 
/*      */     case 5: 
/*   59 */       return new Integer(getInt(val, desc, stmtHandle, conn));
/*      */     
/*      */     case -5: 
/*   62 */       return new Long(getLong(val, desc, stmtHandle, conn));
/*      */     
/*      */     case 2: 
/*      */     case 3: 
/*   66 */       return getBigDecimal(val, desc, stmtHandle, conn);
/*      */     
/*      */     case 7: 
/*   69 */       return new Float(getFloat(val, desc, stmtHandle, conn));
/*      */     
/*      */     case 6: 
/*      */     case 8: 
/*   73 */       double d = getDouble(val, desc, stmtHandle, conn);
/*   74 */       if (sqlType == 6) {
/*   75 */         return new Float(d);
/*      */       }
/*   77 */       return new Double(d);
/*      */     
/*      */     case -1: 
/*      */     case 1: 
/*      */     case 12: 
/*   82 */       return getString(val, desc, stmtHandle, conn, isBdta);
/*      */     
/*      */     case 91: 
/*   85 */       return getDate(val, desc, stmtHandle, conn);
/*      */     
/*      */     case 92: 
/*   88 */       return getTime(val, desc, stmtHandle, conn);
/*      */     
/*      */     case 93: 
/*   91 */       return getTimestamp(val, desc, stmtHandle, conn);
/*      */     
/*      */     case -4: 
/*      */     case -3: 
/*      */     case -2: 
/*   96 */       return getBytes(val, desc, stmtHandle, conn);
/*      */     
/*      */     case 2004: 
/*   99 */       return getBlob(val, desc, conn);
/*      */     
/*      */     case 2005: 
/*  102 */       return getClob(val, desc, conn);
/*      */     
/*      */     case 2003: 
/*  105 */       return getArray_inner(val, desc.getDType(), desc, conn);
/*      */     
/*      */     case 2002: 
/*  108 */       STRUCT struct = getStruct_inner(val, desc.getDType(), desc, conn);
/*  109 */       if (typeName != null)
/*      */       {
/*  111 */         return getStruct_SQLData(map, struct, typeName);
/*      */       }
/*      */       
/*      */ 
/*  115 */       return struct;
/*      */     
/*      */     case 0: 
/*      */     case 2000: 
/*  119 */       return getObject(val, desc, conn, map, typeName);
/*      */     }
/*      */     
/*  122 */     return getBytes(val, desc, stmtHandle, conn);
/*      */   }
/*      */   
/*      */   public static Object getStruct_SQLData(Map typeMap, STRUCT struct, String typeName)
/*      */     throws SQLException
/*      */   {
/*  128 */     if ((typeMap == null) || (typeMap.size() == 0))
/*      */     {
/*  130 */       return struct;
/*      */     }
/*      */     
/*  133 */     Object cls = typeMap.get(typeName);
/*      */     
/*  135 */     if (cls != null)
/*      */     {
/*      */       try
/*      */       {
/*  139 */         Object obj = ((Class)cls).newInstance();
/*  140 */         DmdbSQLInput stream = new DmdbSQLInput(typeMap, struct.getAttributes(typeMap));
/*      */         
/*  142 */         ((SQLData)obj).readSQL(stream, typeName);
/*  143 */         return obj;
/*      */ 
/*      */       }
/*      */       catch (Exception e)
/*      */       {
/*  148 */         DBError.throwSQLException(6007);
/*      */       }
/*      */     }
/*      */     
/*  152 */     return struct;
/*      */   }
/*      */   
/*      */   private static ARRAY getArray_inner(byte[] val, int dtype, CommDesc desc, DmdbConnection_bs conn)
/*      */     throws SQLException
/*      */   {
/*  158 */     TypeDescriptor arrDesc = desc.getTypeDescriptor();
/*  159 */     if (arrDesc == null) {
/*  160 */       DBError.throwSQLException(6007);
/*      */     }
/*  162 */     ARRAY retArr = null;
/*      */     
/*  164 */     switch (dtype)
/*      */     {
/*      */     case 12: 
/*  167 */       Blob lob = getBlob(val, desc, conn);
/*  168 */       retArr = (ARRAY)TypeData.objBlobToObj(lob, arrDesc);
/*  169 */       break;
/*      */     
/*      */     case 117: 
/*  172 */       retArr = TypeData.bytesToArray(val, null, arrDesc);
/*  173 */       break;
/*      */     
/*      */     case 122: 
/*  176 */       retArr = TypeData.bytesToSArray(val, null, arrDesc);
/*  177 */       break;
/*      */     
/*      */     case 119: 
/*  180 */       retArr = (ARRAY)TypeData.bytesToObj(val, null, arrDesc);
/*      */     }
/*      */     
/*      */     
/*  184 */     return retArr;
/*      */   }
/*      */   
/*      */   public static ARRAY getArray(byte[] val, CommDesc desc, DmdbConnection_bs conn) throws SQLException
/*      */   {
/*  189 */     int dtype = desc.getDType();
/*  190 */     if ((dtype != 117) && (dtype != 122) && (dtype != 12) && 
/*  191 */       (dtype != 119)) {
/*  192 */       DBError.throwSQLException(6007);
/*      */     }
/*  194 */     return getArray_inner(val, dtype, desc, conn);
/*      */   }
/*      */   
/*      */   private static STRUCT getStruct_inner(byte[] val, int dtype, CommDesc desc, DmdbConnection_bs conn)
/*      */     throws SQLException
/*      */   {
/*  200 */     STRUCT retStrct = null;
/*  201 */     TypeDescriptor strctDesc = desc.getTypeDescriptor();
/*  202 */     if (strctDesc == null) {
/*  203 */       DBError.throwSQLException(6007);
/*      */     }
/*  205 */     switch (dtype)
/*      */     {
/*      */     case 12: 
/*  208 */       Blob lob = getBlob(val, desc, conn);
/*  209 */       retStrct = (STRUCT)TypeData.objBlobToObj(lob, strctDesc);
/*  210 */       break;
/*      */     
/*      */     case 119: 
/*  213 */       retStrct = (STRUCT)TypeData.bytesToObj(val, null, strctDesc);
/*  214 */       break;
/*      */     
/*      */     case 121: 
/*  217 */       retStrct = TypeData.bytesToRecord(val, null, strctDesc);
/*      */     }
/*      */     
/*      */     
/*  221 */     return retStrct;
/*      */   }
/*      */   
/*      */   public static STRUCT getStruct(byte[] val, CommDesc desc, DmdbConnection_bs conn) throws SQLException
/*      */   {
/*  226 */     int dtype = desc.getDType();
/*  227 */     if ((dtype != 119) && (dtype != 121) && (dtype != 12)) {
/*  228 */       DBError.throwSQLException(6007);
/*      */     }
/*  230 */     return getStruct_inner(val, dtype, desc, conn);
/*      */   }
/*      */   
/*      */   public static String getString(byte[] val, CommDesc desc, int stmtHandle, DmdbConnection_bs conn, boolean isBdta)
/*      */     throws SQLException
/*      */   {
/*  236 */     String str = null;
/*  237 */     CnvtInfo cvtInfo = conn.getCnvtInfo();
/*  238 */     DTypeInfo dtype = desc.getDTypeInfo();
/*  239 */     LobDesc lobInfo = desc.getLobDesc();
/*      */     
/*  241 */     switch (dtype.getDType())
/*      */     {
/*      */     case 0: 
/*      */     case 1: 
/*      */     case 2: 
/*  246 */       byte[] valInner = checkVarchar2(val, dtype.getDType(), dtype.getPrec());
/*      */       
/*  248 */       str = Convertion.getString(valInner, 0, valInner.length, cvtInfo.getServerEncoding());
/*  249 */       break;
/*      */     
/*      */     case 3: 
/*      */     case 4: 
/*      */     case 5: 
/*  254 */       str = String.valueOf(val[0]);
/*  255 */       break;
/*      */     
/*      */     case 6: 
/*  258 */       str = String.valueOf(Convertion.twoByteToShort(val));
/*  259 */       break;
/*      */     
/*      */     case 7: 
/*  262 */       str = String.valueOf(Convertion.fourByteToInt(val));
/*  263 */       break;
/*      */     
/*      */     case 8: 
/*      */     case 24: 
/*  267 */       str = String.valueOf(Convertion.eightByteToLong(val));
/*  268 */       break;
/*      */     
/*      */     case 10: 
/*  271 */       str = String.valueOf(Float.intBitsToFloat(Convertion.fourByteToInt(val)));
/*  272 */       break;
/*      */     
/*      */     case 11: 
/*  275 */       str = String.valueOf(Double.longBitsToDouble(Convertion.eightByteToLong(val)));
/*  276 */       break;
/*      */     
/*      */     case 9: 
/*  279 */       str = String.valueOf(Convertion.bytesToBigDecimal(val, dtype.getScale(), dtype.getPrec()));
/*  280 */       break;
/*      */     
/*      */     case 17: 
/*      */     case 18: 
/*  284 */       str = Convertion.bytesToHexString(val);
/*  285 */       break;
/*      */     
/*      */     case 12: 
/*      */     case 19: 
/*  289 */       if (lobInfo == null) {
/*  290 */         DBError.throwSQLException(6007);
/*      */       }
/*  292 */       byte[] tmp = Convertion.getBytesFrmLob(val, dtype, lobInfo, stmtHandle, conn);
/*  293 */       if (dtype.getDType() == 12) {
/*  294 */         str = Convertion.bytesToHexString(tmp);
/*      */       } else
/*  296 */         str = Convertion.getString(tmp, 0, tmp.length, cvtInfo.getServerEncoding());
/*  297 */       break;
/*      */     
/*      */     case 14: 
/*  300 */       DmdbDateTime date = new DmdbDateTime(val, dtype.getDType(), dtype.getScale(), 
/*  301 */         cvtInfo.getDbTz(), cvtInfo.getTimeZone());
/*  302 */       str = date.getDateInString();
/*  303 */       break;
/*      */     
/*      */     case 15: 
/*  306 */       DmdbDateTime dt = new DmdbDateTime(val, dtype.getDType(), dtype.getScale(), 
/*  307 */         cvtInfo.getDbTz(), cvtInfo.getTimeZone());
/*  308 */       str = dt.getTimeInString();
/*  309 */       break;
/*      */     
/*      */     case 16: 
/*  312 */       DmdbDateTime ts = new DmdbDateTime(val, dtype.getDType(), dtype.getScale(), 
/*  313 */         cvtInfo.getDbTz(), cvtInfo.getTimeZone());
/*  314 */       str = ts.getTimestampInString();
/*  315 */       break;
/*      */     
/*      */     case 21: 
/*  318 */       DmdbIntervalDT intvDt = Convertion.bytesToInterDT(val, dtype.getScale());
/*  319 */       str = intvDt.getDTString();
/*  320 */       break;
/*      */     
/*      */     case 20: 
/*  323 */       DmdbIntervalYM intvYm = Convertion.bytesToInterYM(val, dtype.getScale());
/*  324 */       str = intvYm.getYMString();
/*  325 */       break;
/*      */     
/*      */     case 22: 
/*  328 */       if (isBdta)
/*      */       {
/*  330 */         DmdbTimeZone2Bdta tz = new DmdbTimeZone2Bdta(val, dtype.getScale(), 1);
/*  331 */         str = tz.getStrFromTZ();
/*      */       }
/*      */       else
/*      */       {
/*  335 */         DmdbTimeZone tz = Convertion.bytesToTimeZone(val, dtype.getScale());
/*  336 */         str = tz.getStrFromTZ();
/*      */       }
/*  338 */       break;
/*      */     
/*      */     case 23: 
/*  341 */       if (isBdta)
/*      */       {
/*  343 */         DmdbTimeZone2Bdta tz = new DmdbTimeZone2Bdta(val, dtype.getScale(), 2);
/*  344 */         str = tz.getStrFromTZ();
/*      */       }
/*      */       else
/*      */       {
/*  348 */         DmdbTimeZone tz1 = Convertion.bytesToDateTimeZone(val, dtype.getScale());
/*  349 */         str = tz1.getStrFromTZ();
/*      */       }
/*  351 */       break;
/*      */     case 13: 
/*      */     default: 
/*  354 */       DBError.throwSQLException(6007);
/*      */     }
/*      */     
/*  357 */     return str;
/*      */   }
/*      */   
/*      */   public static boolean getBoolean(byte[] val, CommDesc desc, int stmtHandle, DmdbConnection_bs conn)
/*      */     throws SQLException
/*      */   {
/*  363 */     boolean bl = false;
/*  364 */     CnvtInfo cvtInfo = conn.getCnvtInfo();
/*  365 */     DTypeInfo dtype = desc.getDTypeInfo();
/*  366 */     LobDesc lobInfo = desc.getLobDesc();
/*      */     
/*  368 */     switch (dtype.getDType())
/*      */     {
/*      */     case 3: 
/*      */     case 4: 
/*      */     case 5: 
/*  373 */       bl = Convertion.bytesToBoolean(val);
/*  374 */       break;
/*      */     case 6: 
/*  376 */       if (Convertion.twoByteToShort(val) == 0) {
/*  377 */         bl = false;
/*      */       } else
/*  379 */         bl = true;
/*  380 */       break;
/*      */     case 7: 
/*  382 */       if (Convertion.fourByteToInt(val) == 0) {
/*  383 */         bl = false;
/*      */       } else
/*  385 */         bl = true;
/*  386 */       break;
/*      */     case 8: 
/*      */     case 24: 
/*  389 */       if (Convertion.eightByteToLong(val) == 0L) {
/*  390 */         bl = false;
/*      */       } else
/*  392 */         bl = true;
/*  393 */       break;
/*      */     case 10: 
/*  395 */       if (Float.intBitsToFloat(Convertion.fourByteToInt(val)) == 0.0D) {
/*  396 */         bl = false;
/*      */       } else
/*  398 */         bl = true;
/*  399 */       break;
/*      */     case 11: 
/*  401 */       if (Double.longBitsToDouble(Convertion.eightByteToLong(val)) == 0.0D) {
/*  402 */         bl = false;
/*      */       } else
/*  404 */         bl = true;
/*  405 */       break;
/*      */     case 9: 
/*  407 */       if (Convertion.bytesToBigDecimal(val, dtype.getScale(), dtype.getPrec()).byteValue() == 0) {
/*  408 */         bl = false;
/*      */       } else
/*  410 */         bl = true;
/*  411 */       break;
/*      */     
/*      */     case 0: 
/*      */     case 1: 
/*      */     case 2: 
/*      */     case 19: 
/*  417 */       String str = "";
/*  418 */       byte[] valInner = checkVarchar2(val, dtype.getDType(), dtype.getPrec());
/*  419 */       if (dtype.getDType() == 19)
/*      */       {
/*  421 */         byte[] tmp = Convertion.getBytesFrmLob(valInner, dtype, lobInfo, stmtHandle, conn);
/*  422 */         str = Convertion.getString(tmp, 0, tmp.length, cvtInfo.getServerEncoding());
/*      */       }
/*      */       else {
/*  425 */         str = Convertion.getString(valInner, 0, valInner.length, cvtInfo.getServerEncoding());
/*      */       }
/*  427 */       if ((str.length() == 0) || (str.charAt(0) == '0')) {
/*  428 */         bl = false;
/*      */       } else
/*  430 */         bl = true;
/*  431 */       break;
/*      */     case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 20: case 21: case 22: case 23: default: 
/*  433 */       DBError.throwSQLException(6007);
/*      */     }
/*      */     
/*  436 */     return bl;
/*      */   }
/*      */   
/*      */   public static byte getByte(byte[] val, CommDesc desc, int stmtHandle, DmdbConnection_bs conn)
/*      */     throws SQLException
/*      */   {
/*  442 */     CnvtInfo cvtInfo = conn.getCnvtInfo();
/*  443 */     DTypeInfo dtype = desc.getDTypeInfo();
/*  444 */     LobDesc lobInfo = desc.getLobDesc();
/*      */     
/*  446 */     int type = dtype.getDType();
/*  447 */     switch (type)
/*      */     {
/*      */     case 3: 
/*      */     case 4: 
/*      */     case 5: 
/*      */     case 12: 
/*  453 */       byte[] tmpBs = val;
/*  454 */       if (type == 12)
/*      */       {
/*  456 */         if (desc.getLobDesc() == null)
/*      */         {
/*  458 */           DBError.throwSQLException(6007);
/*      */         }
/*  460 */         tmpBs = Convertion.getBytesFrmLob(val, dtype, lobInfo, stmtHandle, conn);
/*      */       }
/*      */       
/*  463 */       if ((tmpBs == null) || (tmpBs.length == 0)) {
/*  464 */         return 0;
/*      */       }
/*  466 */       return tmpBs[0];
/*      */     
/*      */     case 6: 
/*  469 */       Short tmp = new Short(Convertion.twoByteToShort(val));
/*  470 */       if ((tmp.shortValue() < -128) || (tmp.shortValue() > 127))
/*  471 */         DBError.throwSQLException(6004);
/*  472 */       return tmp.byteValue();
/*      */     
/*      */ 
/*      */     case 7: 
/*  476 */       Integer tmp = new Integer(Convertion.fourByteToInt(val));
/*  477 */       if ((tmp.intValue() < -128) || (tmp.intValue() > 127))
/*  478 */         DBError.throwSQLException(6004);
/*  479 */       return tmp.byteValue();
/*      */     
/*      */ 
/*      */     case 8: 
/*      */     case 24: 
/*  484 */       Long tmp = new Long(Convertion.eightByteToLong(val));
/*  485 */       if ((tmp.longValue() < -128L) || (tmp.longValue() > 127L))
/*  486 */         DBError.throwSQLException(6004);
/*  487 */       return tmp.byteValue();
/*      */     
/*      */ 
/*      */     case 10: 
/*  491 */       Float tmp = new Float(Float.intBitsToFloat(Convertion.fourByteToInt(val)));
/*  492 */       if ((tmp.floatValue() < -128.0F) || (tmp.floatValue() > 127.0F))
/*  493 */         DBError.throwSQLException(6004);
/*  494 */       return tmp.byteValue();
/*      */     
/*      */ 
/*      */     case 11: 
/*  498 */       Double tmp = new Double(Double.longBitsToDouble(Convertion.eightByteToLong(val)));
/*  499 */       if ((tmp.doubleValue() < -128.0D) || (tmp.doubleValue() > 127.0D))
/*  500 */         DBError.throwSQLException(6004);
/*  501 */       return tmp.byteValue();
/*      */     
/*      */ 
/*      */     case 9: 
/*  505 */       BigDecimal tmp = Convertion.bytesToBigDecimal(val, dtype.getScale(), dtype.getPrec());
/*  506 */       if ((tmp.doubleValue() < -128.0D) || (tmp.doubleValue() > 127.0D))
/*  507 */         DBError.throwSQLException(6004);
/*  508 */       return tmp.byteValue();
/*      */     
/*      */ 
/*      */     case 0: 
/*      */     case 1: 
/*      */     case 2: 
/*      */     case 19: 
/*  515 */       String str = "";
/*  516 */       byte[] valInner = checkVarchar2(val, dtype.getDType(), dtype.getPrec());
/*  517 */       if (type == 19)
/*      */       {
/*  519 */         if (lobInfo == null)
/*      */         {
/*  521 */           DBError.throwSQLException(6007);
/*      */         }
/*  523 */         byte[] tmp = Convertion.getBytesFrmLob(valInner, dtype, lobInfo, stmtHandle, conn);
/*  524 */         str = Convertion.getString(tmp, 0, tmp.length, cvtInfo.getServerEncoding());
/*      */       }
/*      */       else {
/*  527 */         str = Convertion.getString(valInner, 0, valInner.length, cvtInfo.getServerEncoding());
/*      */       }
/*  529 */       Double tmp = null;
/*      */       try
/*      */       {
/*  532 */         tmp = Double.valueOf(str.trim());
/*      */       }
/*      */       catch (Exception e)
/*      */       {
/*  536 */         DBError.throwSQLException(6007);
/*      */       }
/*  538 */       if ((tmp.doubleValue() < -128.0D) || (tmp.doubleValue() > 127.0D))
/*  539 */         DBError.throwSQLException(6004);
/*  540 */       return tmp.byteValue();
/*      */     }
/*      */     
/*  543 */     DBError.throwSQLException(6007);
/*      */     
/*      */ 
/*  546 */     return 0;
/*      */   }
/*      */   
/*      */   public static short getShort(byte[] val, CommDesc desc, int stmtHandle, DmdbConnection_bs conn)
/*      */     throws SQLException
/*      */   {
/*  552 */     short result = 0;
/*      */     
/*  554 */     CnvtInfo cvtInfo = conn.getCnvtInfo();
/*  555 */     DTypeInfo dtype = desc.getDTypeInfo();
/*  556 */     LobDesc lobInfo = desc.getLobDesc();
/*  557 */     int type = dtype.getDType();
/*      */     
/*  559 */     switch (type)
/*      */     {
/*      */     case 6: 
/*  562 */       result = Convertion.twoByteToShort(val);
/*  563 */       break;
/*      */     case 3: 
/*      */     case 4: 
/*      */     case 5: 
/*  567 */       if ((val == null) || (val.length == 0)) {
/*  568 */         result = 0;
/*      */       } else
/*  570 */         result = val[0];
/*  571 */       break;
/*      */     
/*      */     case 7: 
/*  574 */       int tmp1 = Convertion.fourByteToInt(val);
/*  575 */       if ((tmp1 < 32768) || (tmp1 > 32767))
/*  576 */         DBError.throwSQLException(6004);
/*  577 */       result = (short)tmp1;
/*  578 */       break;
/*      */     
/*      */ 
/*      */     case 8: 
/*      */     case 24: 
/*  583 */       long tmp1 = Convertion.eightByteToLong(val);
/*  584 */       if ((tmp1 < -32768L) || (tmp1 > 32767L))
/*  585 */         DBError.throwSQLException(6004);
/*  586 */       result = (short)(int)tmp1;
/*  587 */       break;
/*      */     
/*      */ 
/*      */     case 10: 
/*  591 */       float tmp1 = Float.intBitsToFloat(Convertion.fourByteToInt(val));
/*  592 */       if ((tmp1 < -32768.0F) || (tmp1 > 32767.0F))
/*  593 */         DBError.throwSQLException(6004);
/*  594 */       result = (short)(int)tmp1;
/*  595 */       break;
/*      */     
/*      */ 
/*      */     case 11: 
/*  599 */       double tmp1 = Double.longBitsToDouble(Convertion.eightByteToLong(val));
/*  600 */       if ((tmp1 < -32768.0D) || (tmp1 > 32767.0D))
/*  601 */         DBError.throwSQLException(6004);
/*  602 */       result = (short)(int)tmp1;
/*  603 */       break;
/*      */     
/*      */ 
/*      */     case 9: 
/*  607 */       BigDecimal tmp = Convertion.bytesToBigDecimal(val, dtype.getScale(), dtype.getPrec());
/*  608 */       if ((tmp.doubleValue() < -32768.0D) || (tmp.doubleValue() > 32767.0D))
/*  609 */         DBError.throwSQLException(6004);
/*  610 */       result = tmp.shortValue();
/*  611 */       break;
/*      */     
/*      */ 
/*      */     case 0: 
/*      */     case 1: 
/*      */     case 2: 
/*      */     case 19: 
/*  618 */       String str = "";
/*  619 */       byte[] valInner = checkVarchar2(val, dtype.getDType(), dtype.getPrec());
/*  620 */       if (type == 19)
/*      */       {
/*  622 */         if (lobInfo == null)
/*      */         {
/*  624 */           DBError.throwSQLException(6007);
/*      */         }
/*  626 */         byte[] tmp = Convertion.getBytesFrmLob(valInner, dtype, lobInfo, stmtHandle, conn);
/*  627 */         str = Convertion.getString(tmp, 0, tmp.length, cvtInfo.getServerEncoding());
/*      */       }
/*      */       else {
/*  630 */         str = Convertion.getString(valInner, 0, valInner.length, cvtInfo.getServerEncoding());
/*      */       }
/*  632 */       Double tmp1 = null;
/*      */       try
/*      */       {
/*  635 */         tmp1 = Double.valueOf(str.trim());
/*      */       }
/*      */       catch (Exception e)
/*      */       {
/*  639 */         DBError.throwSQLException(6007);
/*      */       }
/*  641 */       if ((tmp1.doubleValue() < -32768.0D) || (tmp1.doubleValue() > 32767.0D))
/*  642 */         DBError.throwSQLException(6004);
/*  643 */       result = tmp1.shortValue();
/*  644 */       break;
/*      */     case 12: case 13: case 14: case 15: case 16: case 17: 
/*      */     case 18: case 20: case 21: case 22: case 23: default: 
/*  647 */       DBError.throwSQLException(6007);
/*      */     }
/*  649 */     return result;
/*      */   }
/*      */   
/*      */   public static int getInt(byte[] val, CommDesc desc, int stmtHandle, DmdbConnection_bs conn)
/*      */     throws SQLException
/*      */   {
/*  655 */     CnvtInfo cvtInfo = conn.getCnvtInfo();
/*  656 */     DTypeInfo dtype = desc.getDTypeInfo();
/*  657 */     LobDesc lobInfo = desc.getLobDesc();
/*      */     
/*  659 */     int type = dtype.getDType();
/*  660 */     int result = 0;
/*      */     
/*  662 */     switch (type)
/*      */     {
/*      */     case 7: 
/*  665 */       result = Convertion.fourByteToInt(val);
/*  666 */       break;
/*      */     case 3: 
/*      */     case 4: 
/*      */     case 5: 
/*      */     case 13: 
/*  671 */       if ((val == null) || (val.length == 0)) {
/*  672 */         result = 0;
/*      */       } else
/*  674 */         result = val[0];
/*  675 */       break;
/*      */     
/*      */     case 6: 
/*  678 */       result = Convertion.twoByteToShort(val);
/*  679 */       break;
/*      */     
/*      */     case 8: 
/*      */     case 24: 
/*  683 */       long tmp1 = Convertion.eightByteToLong(val);
/*  684 */       if ((tmp1 < -2147483648L) || (tmp1 > 2147483647L))
/*  685 */         DBError.throwSQLException(6004);
/*  686 */       result = (int)tmp1;
/*  687 */       break;
/*      */     
/*      */ 
/*      */     case 10: 
/*  691 */       float tmp1 = Float.intBitsToFloat(Convertion.fourByteToInt(val));
/*  692 */       if ((tmp1 < -2.14748365E9F) || (tmp1 > 2.14748365E9F))
/*  693 */         DBError.throwSQLException(6004);
/*  694 */       result = (int)tmp1;
/*  695 */       break;
/*      */     
/*      */ 
/*      */     case 11: 
/*  699 */       double tmp1 = Double.longBitsToDouble(Convertion.eightByteToLong(val));
/*  700 */       if ((tmp1 < -2.147483648E9D) || (tmp1 > 2.147483647E9D))
/*  701 */         DBError.throwSQLException(6004);
/*  702 */       result = (int)tmp1;
/*  703 */       break;
/*      */     
/*      */ 
/*      */     case 9: 
/*  707 */       BigDecimal tmp = Convertion.bytesToBigDecimal(val, dtype.getScale(), dtype.getPrec());
/*      */       
/*  709 */       if ((tmp.doubleValue() < -2.147483648E9D) || (tmp.doubleValue() > 2.147483647E9D))
/*  710 */         DBError.throwSQLException(6004);
/*  711 */       result = tmp.intValue();
/*  712 */       break;
/*      */     
/*      */ 
/*      */     case 0: 
/*      */     case 1: 
/*      */     case 2: 
/*      */     case 19: 
/*  719 */       String str = "";
/*  720 */       byte[] valInner = checkVarchar2(val, dtype.getDType(), dtype.getPrec());
/*  721 */       if (type == 19)
/*      */       {
/*  723 */         if (lobInfo == null)
/*      */         {
/*  725 */           DBError.throwSQLException(6007);
/*      */         }
/*  727 */         byte[] tmp = Convertion.getBytesFrmLob(valInner, dtype, lobInfo, stmtHandle, conn);
/*  728 */         str = Convertion.getString(tmp, 0, tmp.length, cvtInfo.getServerEncoding());
/*      */       }
/*      */       else {
/*  731 */         str = Convertion.getString(valInner, 0, valInner.length, cvtInfo.getServerEncoding());
/*      */       }
/*  733 */       Double tmp1 = null;
/*      */       try
/*      */       {
/*  736 */         tmp1 = Double.valueOf(str.trim());
/*      */       }
/*      */       catch (Exception e)
/*      */       {
/*  740 */         DBError.throwSQLException(6007);
/*      */       }
/*  742 */       if ((tmp1.doubleValue() < -2.147483648E9D) || (tmp1.doubleValue() > 2.147483647E9D))
/*  743 */         DBError.throwSQLException(6004);
/*  744 */       result = tmp1.intValue();
/*  745 */       break;
/*      */     
/*      */     case 17: 
/*      */     case 18: 
/*  749 */       result = Convertion.bytesToInt(val);
/*  750 */       break;
/*      */     case 12: case 14: case 15: case 16: case 20: case 21: case 22: case 23: default: 
/*  752 */       DBError.throwSQLException(6007);
/*      */     }
/*  754 */     return result;
/*      */   }
/*      */   
/*      */   public static long getLong(byte[] val, CommDesc desc, int stmtHandle, DmdbConnection_bs conn)
/*      */     throws SQLException
/*      */   {
/*  760 */     CnvtInfo cvtInfo = conn.getCnvtInfo();
/*  761 */     DTypeInfo dtype = desc.getDTypeInfo();
/*  762 */     LobDesc lobInfo = desc.getLobDesc();
/*      */     
/*  764 */     int type = dtype.getDType();
/*  765 */     long result = 0L;
/*      */     
/*  767 */     switch (type)
/*      */     {
/*      */     case 8: 
/*      */     case 24: 
/*  771 */       result = Convertion.eightByteToLong(val);
/*  772 */       break;
/*      */     case 3: 
/*      */     case 4: 
/*      */     case 5: 
/*  776 */       if ((val == null) || (val.length == 0)) {
/*  777 */         result = 0L;
/*      */       } else
/*  779 */         result = val[0];
/*  780 */       break;
/*      */     case 6: 
/*  782 */       result = Convertion.twoByteToShort(val);
/*  783 */       break;
/*      */     case 7: 
/*  785 */       result = Convertion.fourByteToInt(val);
/*  786 */       break;
/*      */     case 10: 
/*  788 */       result = Float.intBitsToFloat(Convertion.fourByteToInt(val));
/*  789 */       break;
/*      */     case 11: 
/*  791 */       result = Double.longBitsToDouble(Convertion.eightByteToLong(val));
/*  792 */       break;
/*      */     
/*      */     case 9: 
/*  795 */       BigDecimal tmp = Convertion.bytesToBigDecimal(val, dtype.getScale(), dtype.getPrec());
/*      */       
/*  797 */       if ((tmp.doubleValue() < -9.223372036854776E18D) || (tmp.doubleValue() > 9.223372036854776E18D))
/*  798 */         DBError.throwSQLException(6004);
/*  799 */       result = tmp.longValue();
/*  800 */       break;
/*      */     
/*      */ 
/*      */     case 0: 
/*      */     case 1: 
/*      */     case 2: 
/*      */     case 19: 
/*  807 */       String str = "";
/*  808 */       byte[] valInner = checkVarchar2(val, dtype.getDType(), dtype.getPrec());
/*  809 */       if (type == 19)
/*      */       {
/*  811 */         if (lobInfo == null)
/*      */         {
/*  813 */           DBError.throwSQLException(6007);
/*      */         }
/*  815 */         byte[] tmp = Convertion.getBytesFrmLob(valInner, dtype, lobInfo, stmtHandle, conn);
/*  816 */         str = Convertion.getString(tmp, 0, tmp.length, cvtInfo.getServerEncoding());
/*      */       }
/*      */       else {
/*  819 */         str = Convertion.getString(valInner, 0, valInner.length, cvtInfo.getServerEncoding());
/*      */       }
/*  821 */       Double tmp1 = null;
/*      */       try
/*      */       {
/*  824 */         tmp1 = Double.valueOf(str.trim());
/*      */       }
/*      */       catch (Exception e)
/*      */       {
/*  828 */         DBError.throwSQLException(6007);
/*      */       }
/*  830 */       if ((tmp1.doubleValue() < -9.223372036854776E18D) || (tmp1.doubleValue() > 9.223372036854776E18D))
/*  831 */         DBError.throwSQLException(6004);
/*  832 */       result = tmp1.longValue();
/*  833 */       break;
/*      */     
/*      */     case 17: 
/*      */     case 18: 
/*  837 */       result = Convertion.bytesToInt(val);
/*  838 */       break;
/*      */     case 12: case 13: case 14: case 15: case 16: case 20: case 21: case 22: case 23: default: 
/*  840 */       DBError.throwSQLException(6007);
/*      */     }
/*  842 */     return result;
/*      */   }
/*      */   
/*      */   public static float getFloat(byte[] val, CommDesc desc, int stmtHandle, DmdbConnection_bs conn)
/*      */     throws SQLException
/*      */   {
/*  848 */     CnvtInfo cvtInfo = conn.getCnvtInfo();
/*  849 */     DTypeInfo dtype = desc.getDTypeInfo();
/*  850 */     LobDesc lobInfo = desc.getLobDesc();
/*      */     
/*  852 */     int type = dtype.getDType();
/*  853 */     float flt = 0.0F;
/*      */     
/*  855 */     switch (type)
/*      */     {
/*      */     case 10: 
/*  858 */       flt = Float.intBitsToFloat(Convertion.fourByteToInt(val));
/*  859 */       break;
/*      */     case 3: 
/*      */     case 4: 
/*      */     case 5: 
/*  863 */       if ((val == null) || (val.length == 0)) {
/*  864 */         return 0.0F;
/*      */       }
/*  866 */       flt = val[0];
/*  867 */       break;
/*      */     case 6: 
/*  869 */       flt = Convertion.twoByteToShort(val);
/*  870 */       break;
/*      */     case 7: 
/*  872 */       flt = Convertion.fourByteToInt(val);
/*  873 */       break;
/*      */     case 8: 
/*      */     case 24: 
/*  876 */       flt = (float)Convertion.eightByteToLong(val);
/*  877 */       break;
/*      */     case 11: 
/*  879 */       flt = (float)Double.longBitsToDouble(Convertion.eightByteToLong(val));
/*  880 */       break;
/*      */     
/*      */     case 9: 
/*  883 */       BigDecimal tmp = Convertion.bytesToBigDecimal(val, dtype.getScale(), dtype.getPrec());
/*  884 */       flt = tmp.floatValue();
/*  885 */       if ((flt == Float.NEGATIVE_INFINITY) || (flt == Float.POSITIVE_INFINITY))
/*      */       {
/*  887 */         DBError.throwSQLException(6004);
/*      */       }
/*  889 */       break;
/*      */     
/*      */ 
/*      */     case 0: 
/*      */     case 1: 
/*      */     case 2: 
/*      */     case 19: 
/*  896 */       String str = "";
/*  897 */       byte[] valInner = checkVarchar2(val, dtype.getDType(), dtype.getPrec());
/*  898 */       if (type == 19)
/*      */       {
/*  900 */         if (lobInfo == null)
/*      */         {
/*  902 */           DBError.throwSQLException(6007);
/*      */         }
/*  904 */         byte[] tmp = Convertion.getBytesFrmLob(valInner, dtype, lobInfo, stmtHandle, conn);
/*  905 */         str = Convertion.getString(tmp, 0, tmp.length, cvtInfo.getServerEncoding());
/*      */       }
/*      */       else {
/*  908 */         str = Convertion.getString(valInner, 0, valInner.length, cvtInfo.getServerEncoding());
/*      */       }
/*  910 */       BigDecimal tmp1 = null;
/*      */       try
/*      */       {
/*  913 */         tmp1 = new BigDecimal(str.trim());
/*      */       }
/*      */       catch (Exception e)
/*      */       {
/*  917 */         DBError.throwSQLException(6007);
/*      */       }
/*  919 */       flt = tmp1.floatValue();
/*  920 */       if ((flt == Float.NEGATIVE_INFINITY) || (flt == Float.POSITIVE_INFINITY))
/*      */       {
/*  922 */         DBError.throwSQLException(6004);
/*      */       }
/*  924 */       break;
/*      */     case 12: case 13: case 14: case 15: case 16: case 17: 
/*      */     case 18: case 20: case 21: case 22: case 23: default: 
/*  927 */       DBError.throwSQLException(6007);
/*      */     }
/*  929 */     return flt;
/*      */   }
/*      */   
/*      */   public static double getDouble(byte[] val, CommDesc desc, int stmtHandle, DmdbConnection_bs conn)
/*      */     throws SQLException
/*      */   {
/*  935 */     CnvtInfo cvtInfo = conn.getCnvtInfo();
/*  936 */     DTypeInfo dtype = desc.getDTypeInfo();
/*  937 */     LobDesc lobInfo = desc.getLobDesc();
/*      */     
/*  939 */     double dbl = 0.0D;
/*  940 */     int type = dtype.getDType();
/*      */     
/*  942 */     switch (type)
/*      */     {
/*      */     case 11: 
/*  945 */       dbl = Double.longBitsToDouble(Convertion.eightByteToLong(val));
/*  946 */       break;
/*      */     case 3: 
/*      */     case 4: 
/*      */     case 5: 
/*  950 */       if ((val == null) || (val.length == 0)) {
/*  951 */         return 0.0D;
/*      */       }
/*  953 */       dbl = val[0];
/*  954 */       break;
/*      */     case 6: 
/*  956 */       dbl = Convertion.twoByteToShort(val);
/*  957 */       break;
/*      */     case 7: 
/*  959 */       dbl = Convertion.fourByteToInt(val);
/*  960 */       break;
/*      */     case 8: 
/*      */     case 24: 
/*  963 */       dbl = Convertion.eightByteToLong(val);
/*  964 */       break;
/*      */     case 10: 
/*  966 */       dbl = Float.intBitsToFloat(Convertion.fourByteToInt(val));
/*  967 */       break;
/*      */     
/*      */     case 9: 
/*  970 */       BigDecimal tmp = Convertion.bytesToBigDecimal(val, dtype.getScale(), dtype.getPrec());
/*      */       
/*  972 */       dbl = tmp.doubleValue();
/*  973 */       break;
/*      */     
/*      */     case 0: 
/*      */     case 1: 
/*      */     case 2: 
/*      */     case 19: 
/*  979 */       String str = "";
/*  980 */       byte[] valInner = checkVarchar2(val, dtype.getDType(), dtype.getPrec());
/*  981 */       if (type == 19)
/*      */       {
/*  983 */         if (lobInfo == null)
/*      */         {
/*  985 */           DBError.throwSQLException(6007);
/*      */         }
/*  987 */         byte[] tmp = Convertion.getBytesFrmLob(valInner, dtype, lobInfo, stmtHandle, conn);
/*  988 */         str = Convertion.getString(tmp, 0, tmp.length, cvtInfo.getServerEncoding());
/*      */       }
/*      */       else {
/*  991 */         str = Convertion.getString(valInner, 0, valInner.length, cvtInfo.getServerEncoding());
/*      */       }
/*      */       try
/*      */       {
/*  995 */         dbl = Double.valueOf(str.trim()).doubleValue();
/*      */       }
/*      */       catch (Exception e)
/*      */       {
/*  999 */         DBError.throwSQLException(6007);
/*      */       }
/*      */     case 12: case 13: case 14: case 15: case 16: case 17: 
/*      */     case 18: case 20: case 21: case 22: case 23: default: 
/* 1003 */       DBError.throwSQLException(6007);
/*      */     }
/* 1005 */     return dbl;
/*      */   }
/*      */   
/*      */ 
/*      */   public static BigDecimal getBigDecimal(byte[] val, CommDesc desc, int stmtHandle, DmdbConnection_bs conn)
/*      */     throws SQLException
/*      */   {
/* 1012 */     CnvtInfo cvtInfo = conn.getCnvtInfo();
/* 1013 */     DTypeInfo dtype = desc.getDTypeInfo();
/* 1014 */     LobDesc lobInfo = desc.getLobDesc();
/*      */     
/* 1016 */     BigDecimal dec = null;
/* 1017 */     int type = dtype.getDType();
/*      */     
/* 1019 */     switch (type)
/*      */     {
/*      */     case 9: 
/* 1022 */       dec = Convertion.bytesToBigDecimal(val, dtype.getScale(), dtype.getPrec());
/* 1023 */       break;
/*      */     case 3: 
/*      */     case 4: 
/*      */     case 5: 
/* 1027 */       dec = new BigDecimal(BigInteger.valueOf(val[0]));
/* 1028 */       break;
/*      */     case 6: 
/* 1030 */       dec = new BigDecimal(BigInteger.valueOf(Convertion.twoByteToShort(val)));
/* 1031 */       break;
/*      */     case 7: 
/* 1033 */       dec = new BigDecimal(BigInteger.valueOf(Convertion.fourByteToInt(val)));
/* 1034 */       break;
/*      */     case 8: 
/*      */     case 24: 
/* 1037 */       long value = Convertion.eightByteToLong(val);
/* 1038 */       dec = new BigDecimal(BigInteger.valueOf(value));
/* 1039 */       break;
/*      */     case 10: 
/* 1041 */       dec = new BigDecimal(Float.intBitsToFloat(Convertion.fourByteToInt(val)));
/* 1042 */       break;
/*      */     case 11: 
/* 1044 */       dec = new BigDecimal(Double.longBitsToDouble(Convertion.eightByteToLong(val)));
/* 1045 */       break;
/*      */     case 0: 
/*      */     case 1: 
/*      */     case 2: 
/*      */     case 19: 
/* 1050 */       String str = "";
/* 1051 */       byte[] valInner = checkVarchar2(val, dtype.getDType(), dtype.getPrec());
/* 1052 */       if (type == 19)
/*      */       {
/* 1054 */         if (lobInfo == null)
/*      */         {
/* 1056 */           DBError.throwSQLException(6007);
/*      */         }
/* 1058 */         byte[] tmp = Convertion.getBytesFrmLob(valInner, dtype, lobInfo, stmtHandle, conn);
/* 1059 */         str = Convertion.getString(tmp, 0, tmp.length, cvtInfo.getServerEncoding());
/*      */       }
/*      */       else {
/* 1062 */         str = Convertion.getString(valInner, 0, valInner.length, cvtInfo.getServerEncoding());
/*      */       }
/*      */       try
/*      */       {
/* 1066 */         dec = new BigDecimal(str.trim());
/*      */       }
/*      */       catch (Exception e)
/*      */       {
/* 1070 */         DBError.throwSQLException(6007);
/*      */       }
/*      */     case 12: case 13: case 14: case 15: case 16: case 17: 
/*      */     case 18: case 20: case 21: case 22: case 23: default: 
/* 1074 */       DBError.throwSQLException(6007);
/*      */     }
/* 1076 */     return dec;
/*      */   }
/*      */   
/*      */ 
/*      */   public static byte[] getBytes(byte[] val, CommDesc desc, int stmtHandle, DmdbConnection_bs conn)
/*      */     throws SQLException
/*      */   {
/* 1083 */     DTypeInfo dtype = desc.getDTypeInfo();
/* 1084 */     int type = dtype.getDType();
/*      */     
/* 1086 */     switch (type)
/*      */     {
/*      */     case 12: 
/*      */     case 19: 
/* 1090 */       if (desc.getLobDesc() == null)
/*      */       {
/* 1092 */         DBError.throwSQLException(6007);
/*      */       }
/* 1094 */       return Convertion.getBytesFrmLob(val, desc.getDTypeInfo(), desc.getLobDesc(), stmtHandle, 
/* 1095 */         conn);
/*      */     }
/* 1097 */     return val;
/*      */   }
/*      */   
/*      */ 
/*      */   public static Date getDate(byte[] val, CommDesc desc, int stmtHandle, DmdbConnection_bs conn)
/*      */     throws SQLException
/*      */   {
/* 1104 */     CnvtInfo cvtInfo = conn.getCnvtInfo();
/* 1105 */     DTypeInfo dtype = desc.getDTypeInfo();
/* 1106 */     LobDesc lobInfo = desc.getLobDesc();
/*      */     
/* 1108 */     int type = dtype.getDType();
/* 1109 */     int scale = dtype.getScale();
/*      */     
/* 1111 */     DmdbDateTime dt = new DmdbDateTime(val, type, scale, cvtInfo.getDbTz(), cvtInfo.getTimeZone());
/* 1112 */     switch (type)
/*      */     {
/*      */     case 14: 
/* 1115 */       return dt.getDate();
/*      */     
/*      */     case 16: 
/*      */     case 23: 
/* 1119 */       return new Date(dt.getTimestamp().getTime());
/*      */     
/*      */     case 0: 
/*      */     case 1: 
/*      */     case 2: 
/*      */     case 19: 
/* 1125 */       String str = "";
/* 1126 */       byte[] valInner = checkVarchar2(val, dtype.getDType(), dtype.getPrec());
/* 1127 */       if (type == 19)
/*      */       {
/* 1129 */         if (lobInfo == null)
/*      */         {
/* 1131 */           DBError.throwSQLException(6007);
/*      */         }
/* 1133 */         byte[] tmp = Convertion.getBytesFrmLob(valInner, dtype, lobInfo, stmtHandle, conn);
/* 1134 */         str = Convertion.getString(tmp, 0, tmp.length, cvtInfo.getServerEncoding());
/*      */       }
/*      */       else {
/* 1137 */         str = Convertion.getString(valInner, 0, valInner.length, cvtInfo.getServerEncoding());
/*      */       }
/* 1139 */       return DmdbDateTime.getDateByString(str.trim());
/*      */     }
/* 1141 */     DBError.throwSQLException(6007);
/*      */     
/*      */ 
/* 1144 */     return null;
/*      */   }
/*      */   
/*      */   public static Time getTime(byte[] val, CommDesc desc, int stmtHandle, DmdbConnection_bs conn)
/*      */     throws SQLException
/*      */   {
/* 1150 */     CnvtInfo cvtInfo = conn.getCnvtInfo();
/* 1151 */     DTypeInfo dtype = desc.getDTypeInfo();
/* 1152 */     LobDesc lobInfo = desc.getLobDesc();
/*      */     
/* 1154 */     int type = dtype.getDType();
/* 1155 */     int scale = dtype.getScale();
/*      */     
/* 1157 */     DmdbDateTime dt = new DmdbDateTime(val, type, scale, cvtInfo.getDbTz(), cvtInfo.getTimeZone());
/*      */     
/* 1159 */     switch (type)
/*      */     {
/*      */     case 15: 
/*      */     case 22: 
/* 1163 */       return dt.getTime();
/*      */     
/*      */     case 16: 
/*      */     case 23: 
/* 1167 */       return new Time(dt.getTimestamp().getTime());
/*      */     
/*      */ 
/*      */     case 0: 
/*      */     case 1: 
/*      */     case 2: 
/*      */     case 19: 
/* 1174 */       String str = "";
/* 1175 */       byte[] valInner = checkVarchar2(val, dtype.getDType(), dtype.getPrec());
/* 1176 */       if (type == 19)
/*      */       {
/* 1178 */         if (lobInfo == null)
/*      */         {
/* 1180 */           DBError.throwSQLException(6007);
/*      */         }
/* 1182 */         byte[] tmp = Convertion.getBytesFrmLob(valInner, dtype, lobInfo, stmtHandle, conn);
/* 1183 */         str = Convertion.getString(tmp, 0, tmp.length, cvtInfo.getServerEncoding());
/*      */       }
/*      */       else {
/* 1186 */         str = Convertion.getString(valInner, 0, valInner.length, cvtInfo.getServerEncoding());
/*      */       }
/* 1188 */       DmdbTime dt1 = new DmdbTime(str.trim(), scale);
/* 1189 */       return dt1.getTime();
/*      */     }
/*      */     
/* 1192 */     DBError.throwSQLException(6007);
/*      */     
/* 1194 */     return null;
/*      */   }
/*      */   
/*      */ 
/*      */   public static DmdbTime getDmTime(byte[] val, CommDesc desc, int stmtHandle, DmdbConnection_bs conn, boolean isBdta)
/*      */     throws SQLException
/*      */   {
/* 1201 */     DTypeInfo dtype = desc.getDTypeInfo();
/* 1202 */     CnvtInfo cvtInfo = conn.getCnvtInfo();
/*      */     
/* 1204 */     int type = dtype.getDType();
/* 1205 */     int scale = dtype.getScale();
/*      */     
/* 1207 */     DmdbDateTime dt = new DmdbDateTime(val, type, scale, cvtInfo.getDbTz(), cvtInfo.getTimeZone());
/* 1208 */     String str = "";
/*      */     
/* 1210 */     switch (type)
/*      */     {
/*      */     case 15: 
/* 1213 */       return new DmdbTime(val, scale);
/*      */     
/*      */     case 16: 
/* 1216 */       Timestamp ts = dt.getTimestamp();
/* 1217 */       str = String.valueOf(ts);
/* 1218 */       return new DmdbTime(str, scale);
/*      */     }
/*      */     
/* 1221 */     str = getString(val, desc, stmtHandle, conn, isBdta);
/* 1222 */     return new DmdbTime(str, scale);
/*      */   }
/*      */   
/*      */ 
/*      */   public static Timestamp getTimestamp(byte[] val, CommDesc desc, int stmtHandle, DmdbConnection_bs conn)
/*      */     throws SQLException
/*      */   {
/* 1229 */     CnvtInfo cvtInfo = conn.getCnvtInfo();
/* 1230 */     DTypeInfo dtype = desc.getDTypeInfo();
/* 1231 */     LobDesc lobInfo = desc.getLobDesc();
/*      */     
/* 1233 */     int type = dtype.getDType();
/* 1234 */     int scale = dtype.getScale();
/*      */     
/* 1236 */     DmdbDateTime dt = new DmdbDateTime(val, type, scale, cvtInfo.getDbTz(), cvtInfo.getTimeZone());
/*      */     
/* 1238 */     switch (type)
/*      */     {
/*      */     case 16: 
/*      */     case 23: 
/* 1242 */       return dt.getTimestamp();
/*      */     
/*      */     case 14: 
/* 1245 */       return new Timestamp(dt.getDate().getTime());
/*      */     
/*      */ 
/*      */     case 15: 
/*      */     case 22: 
/* 1250 */       DmdbTime dt1 = new DmdbTime(val, scale);
/* 1251 */       return dt1.getTimestamp();
/*      */     
/*      */     case 0: 
/*      */     case 1: 
/*      */     case 2: 
/*      */     case 19: 
/* 1257 */       String str = "";
/* 1258 */       byte[] valInner = checkVarchar2(val, dtype.getDType(), dtype.getPrec());
/* 1259 */       if (type == 19)
/*      */       {
/* 1261 */         if (lobInfo == null)
/*      */         {
/* 1263 */           DBError.throwSQLException(6007);
/*      */         }
/* 1265 */         byte[] tmp = Convertion.getBytesFrmLob(valInner, dtype, lobInfo, stmtHandle, conn);
/* 1266 */         str = Convertion.getString(tmp, 0, tmp.length, cvtInfo.getServerEncoding());
/*      */       }
/*      */       else {
/* 1269 */         str = Convertion.getString(valInner, 0, valInner.length, cvtInfo.getServerEncoding());
/*      */       }
/* 1271 */       return DmdbDateTime.getTimestampByString(str.trim(), type, scale, cvtInfo.getTimeZone());
/*      */     }
/* 1273 */     DBError.throwSQLException(6007);
/*      */     
/* 1275 */     return null;
/*      */   }
/*      */   
/*      */   public static InputStream getAsciiStream(byte[] val, CommDesc desc, DmdbConnection_bs conn)
/*      */     throws SQLException
/*      */   {
/* 1281 */     CnvtInfo cvtInfo = conn.getCnvtInfo();
/* 1282 */     DTypeInfo dtype = desc.getDTypeInfo();
/* 1283 */     LobDesc lobInfo = desc.getLobDesc();
/*      */     
/* 1285 */     int type = dtype.getDType();
/* 1286 */     int prec = dtype.getPrec();
/*      */     
/*      */ 
/* 1289 */     boolean fromRowSetFlag = false;
/* 1290 */     switch (type)
/*      */     {
/*      */ 
/*      */     case 17: 
/*      */     case 18: 
/* 1295 */       return new DmdbInputStream(val, false, cvtInfo.getServerEncoding());
/*      */     case 12: 
/* 1297 */       Blob blob = get_blob_value(val, lobInfo, conn, !desc.isReadOnly());
/* 1298 */       return new DmdbInputStream(blob, fromRowSetFlag, conn.getServerEncoding());
/*      */     case 19: 
/* 1300 */       Clob clob = get_clob_value(val, lobInfo, conn, !desc.isReadOnly());
/* 1301 */       return new DmdbInputStream(clob, fromRowSetFlag, conn.getServerEncoding());
/*      */     case 0: 
/*      */     case 1: 
/*      */     case 2: 
/* 1305 */       byte[] valInner = checkVarchar2(val, type, prec);
/* 1306 */       return new DmdbInputStream(valInner, false, cvtInfo.getServerEncoding()); }
/*      */     
/* 1308 */     DBError.throwSQLException(6016);
/*      */     
/* 1310 */     return null;
/*      */   }
/*      */   
/*      */   public static InputStream getUnicodeStream(byte[] val, CommDesc desc, DmdbConnection_bs conn)
/*      */     throws SQLException
/*      */   {
/* 1316 */     DTypeInfo dtype = desc.getDTypeInfo();
/* 1317 */     LobDesc lobInfo = desc.getLobDesc();
/*      */     
/* 1319 */     InputStream in = null;
/*      */     
/* 1321 */     int type = dtype.getDType();
/* 1322 */     boolean fromRowSetFlag = false;
/* 1323 */     switch (type)
/*      */     {
/*      */     case 12: 
/*      */     case 17: 
/*      */     case 18: 
/* 1328 */       if (type == 12)
/*      */       {
/* 1330 */         Blob blob = get_blob_value(val, lobInfo, conn, !desc.isReadOnly());
/* 1331 */         in = new DmdbInputStream(blob, fromRowSetFlag, conn.getServerEncoding());
/*      */       }
/*      */       else
/*      */       {
/* 1335 */         String str = Convertion.bytesToHexString(val);
/* 1336 */         in = new ByteArrayInputStream(str.getBytes());
/*      */       }
/* 1338 */       return new UtilBinaryToUnicodeInputStream(in);
/*      */     case 19: 
/* 1340 */       Clob clob = get_clob_value(val, lobInfo, conn, !desc.isReadOnly());
/* 1341 */       in = new DmdbInputStream(clob, fromRowSetFlag, conn.getServerEncoding());
/* 1342 */       return new UtilBinaryToUnicodeInputStream(in);
/*      */     case 0: 
/*      */     case 1: 
/*      */     case 2: 
/* 1346 */       byte[] valInner = checkVarchar2(val, type, dtype.getPrec());
/* 1347 */       in = new ByteArrayInputStream(valInner);
/* 1348 */       return new UtilBinaryToUnicodeInputStream(in);
/*      */     }
/* 1350 */     DBError.throwSQLException(6016);
/*      */     
/* 1352 */     return null;
/*      */   }
/*      */   
/*      */ 
/*      */   public static InputStream getBinaryStream(byte[] val, CommDesc desc, DmdbConnection_bs conn)
/*      */     throws SQLException
/*      */   {
/* 1359 */     CnvtInfo cvtInfo = conn.getCnvtInfo();
/* 1360 */     DTypeInfo dtype = desc.getDTypeInfo();
/* 1361 */     LobDesc lobInfo = desc.getLobDesc();
/*      */     
/* 1363 */     int type = dtype.getDType();
/*      */     
/*      */ 
/* 1366 */     boolean fromRowSetFlag = false;
/* 1367 */     switch (type)
/*      */     {
/*      */     case 17: 
/*      */     case 18: 
/* 1371 */       return new DmdbInputStream(val, fromRowSetFlag, cvtInfo.getServerEncoding());
/*      */     case 12: 
/* 1373 */       Blob blob = get_blob_value(val, lobInfo, conn, !desc.isReadOnly());
/* 1374 */       return new DmdbInputStream(blob, fromRowSetFlag, conn.getServerEncoding());
/*      */     case 19: 
/* 1376 */       Clob clob = get_clob_value(val, lobInfo, conn, !desc.isReadOnly());
/* 1377 */       return new DmdbInputStream(clob, fromRowSetFlag, conn.getServerEncoding());
/*      */     case 0: 
/*      */     case 1: 
/* 1380 */       byte[] valInner = checkVarchar2(val, type, dtype.getPrec());
/* 1381 */       return new DmdbInputStream(valInner, fromRowSetFlag, cvtInfo.getServerEncoding());
/*      */     }
/* 1383 */     DBError.throwSQLException(6016);
/*      */     
/*      */ 
/* 1386 */     return null;
/*      */   }
/*      */   
/*      */   public static Object getObject(byte[] val, CommDesc desc, DmdbConnection_bs conn, Map map, String typeName)
/*      */     throws SQLException
/*      */   {
/* 1392 */     CnvtInfo cvtInfo = conn.getCnvtInfo();
/* 1393 */     DTypeInfo dtype = desc.getDTypeInfo();
/* 1394 */     LobDesc lobInfo = desc.getLobDesc();
/*      */     
/* 1396 */     int type = dtype.getDType();
/* 1397 */     int scale = dtype.getScale();
/* 1398 */     int prec = dtype.getPrec();
/*      */     
/* 1400 */     switch (type)
/*      */     {
/*      */     case 3: 
/*      */     case 4: 
/* 1404 */       return new Boolean(Convertion.bytesToBoolean(val));
/*      */     case 5: 
/*      */     case 6: 
/*      */     case 7: 
/* 1408 */       int tmp = 0;
/*      */       
/* 1410 */       if (type == 5) {
/* 1411 */         tmp = val[0];
/* 1412 */       } else if (type == 6) {
/* 1413 */         tmp = Convertion.twoByteToShort(val);
/*      */       } else {
/* 1415 */         tmp = Convertion.fourByteToInt(val);
/*      */       }
/* 1417 */       return new Integer(tmp);
/*      */     case 8: 
/*      */     case 24: 
/* 1420 */       return new Long(Convertion.eightByteToLong(val));
/*      */     case 9: 
/* 1422 */       return Convertion.bytesToBigDecimal(val, scale, prec);
/*      */     case 10: 
/* 1424 */       return new Float(Float.intBitsToFloat(Convertion.fourByteToInt(val)));
/*      */     case 11: 
/* 1426 */       return new Double(Double.longBitsToDouble(Convertion.eightByteToLong(val)));
/*      */     case 14: 
/* 1428 */       return Convertion.bytesToDate(val, scale, cvtInfo.getDbTz(), cvtInfo.getTimeZone());
/*      */     case 15: 
/* 1430 */       return Convertion.bytesToTime(val, scale, cvtInfo.getDbTz(), cvtInfo.getTimeZone());
/*      */     case 16: 
/* 1432 */       return Convertion.bytesToTimeStamp(val, scale, cvtInfo.getDbTz(), cvtInfo.getTimeZone());
/*      */     case 17: 
/*      */     case 18: 
/* 1435 */       return val;
/*      */     case 12: 
/* 1437 */       Blob blob = get_blob_value(val, lobInfo, conn, !desc.isReadOnly());
/*      */       
/* 1439 */       if (desc.isComplexType())
/*      */       {
/* 1441 */         TypeDescriptor typedesc = desc.getTypeDescriptor();
/* 1442 */         if (typedesc != null) {
/* 1443 */           return getComplexObj_from_blob(blob, typedesc);
/*      */         }
/*      */         
/* 1446 */         DBError.throwSQLException(6007);
/* 1447 */         return null;
/*      */       }
/*      */       
/*      */ 
/*      */ 
/* 1452 */       if (desc.getTypeName().equalsIgnoreCase("LONGVARBINARY"))
/*      */       {
/* 1454 */         long length = blob.length();
/* 1455 */         return blob.getBytes(1L, (int)length);
/*      */       }
/*      */       
/* 1458 */       return blob;
/*      */     
/*      */     case 0: 
/*      */     case 1: 
/*      */     case 2: 
/* 1463 */       byte[] valInner = checkVarchar2(val, type, dtype.getPrec());
/* 1464 */       return Convertion.getString(valInner, 0, val.length, cvtInfo.getServerEncoding());
/*      */     case 19: 
/* 1466 */       Clob clob = get_clob_value(val, lobInfo, conn, !desc.isReadOnly());
/* 1467 */       if (desc.getTypeName().equalsIgnoreCase("LONGVARCHAR"))
/*      */       {
/* 1469 */         long length = clob.length();
/* 1470 */         return clob.getSubString(1L, (int)length);
/*      */       }
/*      */       
/*      */ 
/* 1474 */       return clob;
/*      */     
/*      */     case 20: 
/* 1477 */       return Convertion.bytesToInterYM(val, scale);
/*      */     case 21: 
/* 1479 */       return Convertion.bytesToInterDT(val, scale);
/*      */     
/*      */     case 117: 
/*      */     case 122: 
/* 1483 */       return getArray_inner(val, dtype.getDType(), desc, conn);
/*      */     
/*      */     case 119: 
/*      */     case 121: 
/* 1487 */       STRUCT struct = getStruct_inner(val, dtype.getDType(), desc, conn);
/* 1488 */       if (typeName != null)
/*      */       {
/* 1490 */         return getStruct_SQLData(map, struct, typeName);
/*      */       }
/*      */       
/*      */ 
/* 1494 */       return struct;
/*      */     }
/*      */     
/*      */     
/*      */ 
/* 1499 */     DBError.throwSQLException(6007);
/*      */     
/* 1501 */     return null;
/*      */   }
/*      */   
/*      */   private static Object getComplexObj_from_blob(Blob blob, TypeDescriptor desc) throws SQLException
/*      */   {
/* 1506 */     return TypeData.objBlobToObj(blob, desc);
/*      */   }
/*      */   
/*      */   public static Reader getCharacterStream(byte[] val, CommDesc desc, DmdbConnection_bs conn)
/*      */     throws SQLException
/*      */   {
/* 1512 */     CnvtInfo cvtInfo = conn.getCnvtInfo();
/* 1513 */     DTypeInfo dtype = desc.getDTypeInfo();
/* 1514 */     LobDesc lobInfo = desc.getLobDesc();
/*      */     
/* 1516 */     int type = dtype.getDType();
/*      */     
/* 1518 */     switch (type)
/*      */     {
/*      */     case 17: 
/*      */     case 18: 
/* 1522 */       return new BufferedReader(new InputStreamReader(new ByteArrayInputStream(val)));
/*      */     case 12: 
/* 1524 */       Blob blob1 = get_blob_value(val, lobInfo, conn, !desc.isReadOnly());
/* 1525 */       if (blob1 == null) {
/* 1526 */         return null;
/*      */       }
/* 1528 */       return ((DmdbBlob)blob1).getCharacterStream();
/*      */     case 19: 
/* 1530 */       Clob clob1 = get_clob_value(val, lobInfo, conn, !desc.isReadOnly());
/* 1531 */       return clob1.getCharacterStream();
/*      */     case 0: 
/*      */     case 1: 
/*      */     case 2: 
/* 1535 */       byte[] valInner = checkVarchar2(val, type, dtype.getPrec());
/* 1536 */       String str = Convertion.getString(valInner, 0, val.length, cvtInfo.getServerEncoding());
/* 1537 */       return new StringReader(str);
/*      */     }
/* 1539 */     DBError.throwSQLException(6016);
/*      */     
/* 1541 */     return null;
/*      */   }
/*      */   
/*      */   public static Blob getBlob(byte[] val, CommDesc desc, DmdbConnection_bs conn) throws SQLException
/*      */   {
/* 1546 */     int dType = desc.getDTypeInfo().getDType();
/* 1547 */     if (dType != 12) {
/* 1548 */       DBError.throwSQLException(6016);
/*      */     }
/* 1550 */     LobDesc lobInfo = desc.getLobDesc();
/* 1551 */     return get_blob_value(val, lobInfo, conn, !desc.isReadOnly());
/*      */   }
/*      */   
/*      */   public static Clob getClob(byte[] val, CommDesc desc, DmdbConnection_bs conn) throws SQLException
/*      */   {
/* 1556 */     int dType = desc.getDTypeInfo().getDType();
/* 1557 */     if (dType != 19) {
/* 1558 */       DBError.throwSQLException(6016);
/*      */     }
/* 1560 */     LobDesc lobInfo = desc.getLobDesc();
/* 1561 */     return get_clob_value(val, lobInfo, conn, !desc.isReadOnly());
/*      */   }
/*      */   
/*      */   public static DmdbIntervalDT getIntervalDT(byte[] val, CommDesc desc, int stmtHandle, DmdbConnection_bs conn, boolean isBdta)
/*      */     throws SQLException
/*      */   {
/* 1567 */     DTypeInfo dtype = desc.getDTypeInfo();
/*      */     
/* 1569 */     int type = dtype.getDType();
/* 1570 */     int scale = dtype.getScale();
/*      */     
/* 1572 */     switch (type)
/*      */     {
/*      */     case 21: 
/* 1575 */       return Convertion.bytesToInterDT(val, scale);
/*      */     }
/*      */     
/* 1578 */     return new DmdbIntervalDT(getString(val, desc, stmtHandle, conn, isBdta));
/*      */   }
/*      */   
/*      */ 
/*      */   public static DmdbIntervalYM getIntervalYM(byte[] val, CommDesc desc, int stmtHandle, DmdbConnection_bs conn, boolean isBdta)
/*      */     throws SQLException
/*      */   {
/* 1585 */     DTypeInfo dtype = desc.getDTypeInfo();
/*      */     
/* 1587 */     int scale = dtype.getScale();
/* 1588 */     int type = dtype.getDType();
/*      */     
/* 1590 */     switch (type)
/*      */     {
/*      */     case 20: 
/* 1593 */       return Convertion.bytesToInterYM(val, scale);
/*      */     }
/*      */     
/* 1596 */     return new DmdbIntervalYM(getString(val, desc, stmtHandle, conn, isBdta), scale);
/*      */   }
/*      */   
/*      */ 
/*      */   private static Blob get_blob_value(byte[] bs, LobDesc lobInfo, DmdbConnection_bs conn, boolean updatable)
/*      */     throws SQLException
/*      */   {
/* 1603 */     DmdbBlob ret = null;
/*      */     
/* 1605 */     if (lobInfo != null)
/*      */     {
/* 1607 */       ret = new DmdbBlob(bs, lobInfo, conn, updatable);
/*      */       
/* 1609 */       if ((lobInfo.getLobMode() == 2) && (ret != null))
/*      */       {
/* 1611 */         if (!ret.isValueInRow())
/*      */         {
/* 1613 */           int nblob_inrow_hdr_size = ret.nblob_inrow_hdr_size(conn.getNewLobFlag());
/* 1614 */           byte[] tmp = ret.getBytesOffRow(1L, ret.getLobLen());
/* 1615 */           byte[] value = new byte[nblob_inrow_hdr_size + tmp.length];
/* 1616 */           System.arraycopy(ret.m_value, 0, value, 0, nblob_inrow_hdr_size);
/* 1617 */           System.arraycopy(tmp, 0, value, nblob_inrow_hdr_size, tmp.length);
/* 1618 */           ret.m_value = value;
/*      */         }
/*      */       }
/*      */     }
/*      */     else
/*      */     {
/* 1624 */       ret = new DmdbBlob(bs, conn);
/*      */     }
/* 1626 */     return ret;
/*      */   }
/*      */   
/*      */   private static Clob get_clob_value(byte[] bs, LobDesc lobInfo, DmdbConnection_bs conn, boolean updatable)
/*      */     throws SQLException
/*      */   {
/* 1632 */     DmdbClob ret = null;
/*      */     
/* 1634 */     if (lobInfo != null)
/*      */     {
/* 1636 */       ret = new DmdbClob(bs, lobInfo, conn, updatable);
/*      */       
/* 1638 */       if ((lobInfo.getLobMode() == 2) && (ret != null))
/*      */       {
/* 1640 */         if (!ret.isValueInRow())
/*      */         {
/* 1642 */           int nblob_inrow_hdr_size = ret.nblob_inrow_hdr_size(conn.getNewLobFlag());
/* 1643 */           byte[] tmp = ret.getBytesOffRow(1L, ret.getLobLen());
/* 1644 */           byte[] value = new byte[nblob_inrow_hdr_size + tmp.length];
/* 1645 */           System.arraycopy(ret.m_value, 0, value, 0, nblob_inrow_hdr_size);
/* 1646 */           System.arraycopy(tmp, 0, value, nblob_inrow_hdr_size, tmp.length);
/* 1647 */           ret.m_value = value;
/*      */         }
/*      */       }
/*      */     }
/*      */     else
/*      */     {
/* 1653 */       ret = new DmdbClob(bs, conn);
/*      */     }
/* 1655 */     return ret;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public static byte[] checkVarchar2(byte[] val, int dType, int prec)
/*      */   {
/* 1669 */     byte[] retBs = null;
/* 1670 */     if (dType == 1)
/*      */     {
/* 1672 */       retBs = new byte[prec];
/* 1673 */       System.arraycopy(val, 0, retBs, 0, val.length);
/* 1674 */       for (int i = val.length; i < retBs.length; i++) {
/* 1675 */         retBs[i] = 32;
/*      */       }
/*      */     }
/*      */     else {
/* 1679 */       retBs = val;
/*      */     }
/*      */     
/* 1682 */     return retBs;
/*      */   }
/*      */ }


/* Location:              D:\Program Files\DBMS_20150813\jdbc\Dm7JdbcDriver17.jar!\dm\jdbc\dataConvertion\CType2JType.class
 * Java compiler version: 2 (46.0)
 * JD-Core Version:       0.7.1
 */